package com.frxuexi.park2301.user

import androidx.lifecycle.MutableLiveData
import com.frxuexi.lib_base.db.UserDao
import com.frxuexi.lib_base.entity.UserBean
import com.frxuexi.lib_base.entity.UserEntity
import com.frxuexi.lib_base.mvvm.BaseViewModel
import com.frxuexi.lib_base.net.ApiService
import com.frxuexi.lib_base.net.VideoApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class UserViewModel @Inject constructor(val apiService: ApiService, val userDao: UserDao):BaseViewModel() {
    val loginData =MutableLiveData<UserBean>()

    val registerData = MutableLiveData<Long>()
    val loginRoomData =MutableLiveData<UserEntity>()

    fun login(username:String,pwd:String){
        httpRequest({apiService.login(username,pwd)},loginData::postValue)
    }

    fun loginRoom(username:String,pwd:String){
        roomRequest({userDao.login(username,pwd)},loginRoomData::postValue)
    }

    fun register(name:String,pwd: String){
        httpRequest({apiService.register(name,pwd)},{
            roomRequest({userDao.register(UserEntity(null,pwd,5,"",name))},registerData::postValue)
        })
    }


}